package com.gewu.pm.ui.activity.filter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.gewu.pm.R;
import com.gewu.pm.app.AppActivity;
import com.gewu.pm.ui.dialog.SelectSalesRegionDialog;
import com.gewu.pm.ui.dialog.SelectSalespersonDialog;
import com.gewu.pm.ui.dialog.SelectSubmitterDialog;
import com.gewu.pm.ui.dialog.SelectionListDialog;
import com.gewu.pm.ui.dialog.bean.SalespersonBean;
import com.hjq.base.BaseDialog;

import java.util.Arrays;
import java.util.List;

/**
 * 筛选-代支付（订单汇总报表、未下单客户报表、订单总报表、销售区域相同）
 */
public class OldFilterPendingPaymentActivity extends AppActivity {

    private TextView tvDistributor;//配送商
    private TextView tvSalesman;//业务员
    private TextView tvSalesArea;//销售区域
    private TextView tvDepartment;//部门
    private TextView tvType;//类型

    /**
     * 底部按钮
     */
    private TextView tvReset;
    private TextView tvConfirm;


    public static void start(Context context) {
        Intent intent = new Intent(context, OldFilterPendingPaymentActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_filter_pending_payment;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        tvSalesman = findViewById(R.id.tv_salesman);
        tvDistributor = findViewById(R.id.tv_distributor);
        tvSalesArea = findViewById(R.id.tv_sales_area);
        tvDepartment = findViewById(R.id.tv_department);
        tvType = findViewById(R.id.tv_type);
        tvReset = findViewById(R.id.tv_reset);
        tvConfirm = findViewById(R.id.tv_confirm);
        // 设置点击事件
        setOnClickListener(tvSalesman, tvDistributor, tvSalesArea, tvReset, tvConfirm, tvDepartment, tvType);
    }

    @Override
    protected void initData() {

    }

    @Override
    public void onClick(View view) {
        int viewId = view.getId();
        if (viewId == R.id.tv_salesman) {//业务员
            new SelectSalespersonDialog.Builder(this)
                    .setListener(new SelectSalespersonDialog.OnListener() {
                        @Override
                        public void onSelected(BaseDialog dialog, String name, SalespersonBean salesperson) {
                            // 显示选中的业务员
                            tvSalesman.setText(name);
                            tvSalesman.setTextColor(getResources().getColor(R.color.cb3));
                        }
                    })
                    .show();
        } else if (viewId == R.id.tv_distributor) {// 点击配送商
            new SelectSubmitterDialog.Builder(this, 101)//101 = 只显示配送商
                    .setListener(new SelectSubmitterDialog.OnListener() {
                        @Override
                        public void onSelected(BaseDialog dialog, String submitter, int type, Object data) {
                            // 显示选中的提交人
                            tvDistributor.setText(submitter);
                            tvDistributor.setTextColor(getResources().getColor(R.color.cb3));
                        }
                    })
                    .show();

        } else if (viewId == R.id.tv_department) {//部门  暂时写到这里的  很多筛选框 需要改  配送商的筛选是有部门的
            new SelectSubmitterDialog.Builder(this,104)//104 = 只显示部门
                    .setListener(new SelectSubmitterDialog.OnListener() {
                        @Override
                        public void onSelected(BaseDialog dialog, String submitter, int type, Object data) {
                            tvDepartment.setText(submitter);
                            tvDepartment.setTextColor(getResources().getColor(R.color.cb3));
                        }
                    })
                    .show();

        } else if (viewId == R.id.tv_sales_area) {// 点击销售区域，弹出选择对话框
            new SelectSalesRegionDialog.Builder(this)
                    .setDefaultRegion(tvSalesArea.getText().toString())
                    .setListener(new SelectSalesRegionDialog.OnListener() {
                        @Override
                        public void onSelected(BaseDialog dialog, String region) {
                            // 显示选中的区域
                            tvSalesArea.setText(region);
                            tvSalesArea.setTextColor(getResources().getColor(R.color.cb3));
                        }

                        @Override
                        public void onCancel(BaseDialog dialog) {
                            // 取消选择
                        }
                    })
                    .show();

        } else if (viewId == R.id.tv_reset) {
            // 点击重置按钮
            toast("重置，参考FilterSalesActivity");

        } else if (viewId == R.id.tv_confirm) {
            // 点击确定按钮
            toast("确定，参考FilterSalesActivity");
        } else if (viewId == R.id.tv_type) {// 类型
            // 类型数据列表
            List<String> typeList = Arrays.asList("生鲜", "超市", "餐饮", "农贸", "水果店");
            
            new SelectionListDialog.Builder(this)
                    .setTitle("选择类型")
                    .setDataList(typeList)
                    .setDefaultSelection(tvType.getText().toString())
                    .setListener(new SelectionListDialog.OnListener() {
                        @Override
                        public void onSelected(BaseDialog dialog, String selectedItem, int position) {
                            // 显示选中的类型
                            tvType.setText(selectedItem);
                            tvType.setTextColor(getResources().getColor(R.color.cb3));
                        }
                    })
                    .show();
        }
    }
}